package com.springmvc.aop;

import com.springmvc.core.db.DbContextHolder;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Aspect
@Component
@Order(0)
public class DataSourceAspect {

	Logger logger = LoggerFactory.getLogger(DataSourceAspect.class);

	@Pointcut(value = "execution(public * com.springmvc.web.activiti.mapper.*.*(..))")
	private void datasource1ServicePointcut() {
	}

	;


	/**
	 * 切换数据源1
	 */
	@Before("datasource1ServicePointcut()")
	public void dataSource1Interceptor(JoinPoint point) {
		logger.debug("切换到数据源：{}.......", "datasource1");
		DbContextHolder.setDbType(DBTypeEnum.activiti.getValue());
	}
}